import request from './request'

/**
 * 查询所有角色
 */
export const getAllRoles = () => {
  return request({
    url: '/role/list',
    method: 'get'
  })
}

/**
 * 根据角色ID查询角色
 */
export const getRoleById = (roleId) => {
  return request({
    url: `/role/${roleId}`,
    method: 'get'
  })
}

/**
 * 添加角色
 */
export const addRole = (data) => {
  return request({
    url: '/role/add',
    method: 'post',
    data
  })
}

/**
 * 更新角色
 */
export const updateRole = (data) => {
  return request({
    url: '/role/update',
    method: 'put',
    data
  })
}

/**
 * 删除角色
 */
export const deleteRole = (roleId) => {
  return request({
    url: `/role/delete/${roleId}`,
    method: 'delete'
  })
}

/**
 * 为角色分配菜单权限
 */
export const assignMenusToRole = (roleId, menuIds) => {
  return request({
    url: `/role/assignMenus/${roleId}`,
    method: 'post',
    data: menuIds
  })
}

/**
 * 为用户分配角色
 */
export const assignRolesToUser = (userId, roleIds) => {
  return request({
    url: `/role/assign/${userId}`,
    method: 'post',
    data: roleIds
  })
}